<?php
	function writeFile($filename, $content)	{
		$fh = fopen($filename, "w");
		fwrite($fh, $content);
		fclose($fh);
	}
	$version = $_GET['version'];
	require_once('simple_html_dom.php');
	echo "building all.$version.js...<br>";
	$html = file_get_html("index.$version.copy.html");
	$content = "";
	foreach($html->find('script') as $element) 	{
		$src = $element->src;
		$build = $element->build;
		if ($src != null && $src != "" && $build != 'no')	{
			echo $src."<br>";
			$content .= file_get_contents($src)."\n";
		}
	}
	writeFile("static/js/all.$version.js", $content);
	
	echo "<br>building all.$version.css...<br>";
	$content = "";
	foreach($html->find('link') as $element) 	{
		$src = $element->href;
		echo $src."<br>";
		$content .= file_get_contents($src)."\n";
	}
	writeFile("static/css/all.$version.css", $content);
?>